	
var columns= [ { title: '序号',width:'5%',formatter: function (value, row, index) {return index+1;}},
               { title: '名称',field: 'title'},
               { title: '主题', field: 'subject' },
               { title: '拍摄时间', field: 'created' },
               { title: '出处', field: 'sourceForm' },
               { title: '文件大小', field: 'size' },
               { title: '保存位置', field: 'storedin' },
               { title: '发布日期', field: 'published' },
               { title: '状态', formatter: function (value, row, index) {	             	   
            	   if(row.scbz=='0')
				   		return '<font style="color:green;">有效</font>';
            	   else
				   		return '<font style="color:red;">无效</font>';
               }},
               { title: '操作' ,formatter: function (value, row, index) {	             	   
            	   var operateInfo='<a href="javascript:modifyShowData('+row.zdbh+',1)" style="margin-right:10px;">详情</a>';
            	   operateInfo+='<a href="javascript:modifyData('+row.zdbh+')" style="margin-right:10px;">修改</a>';
            	   if(row.scbz=='0')
            		   operateInfo+= '<a href="javascript:setStatus('+row.zdbh+',1)">设为无效</a>';
            	   else
            		   operateInfo+= '<a href="javascript:setStatus('+row.zdbh+',0)">设为有效</a>';
            	   return operateInfo;
               }}
               ];
var columnsThree= [ { title: '序号',width:'5%',formatter: function (value, row, index) {return index+1;}},
                    { title: '名称',field: 'title'},	                
                    { title: '主题', field: 'subject' },
                    { title: '拍摄时间', field: 'created' },
                    { title: '采集单位', field: 'collectionunit' },	
                    { title: '发布日期', field: 'published' },
                    { title: '状态', formatter: function (value, row, index) {	             	   
                    	if(row.scbz=='0')
							return '<font style="color:green;">有效</font>';
                    	else
							return '<font style="color:red;">无效</font>';
                    }},
                    { title: '操作' ,formatter: function (value, row, index) {	             	   
                    	var operateInfo='<a href="javascript:modifyShowData('+row.zdbh+',1)" style="margin-right:10px;">详情</a>';
                    	operateInfo+='<a href="javascript:modifyData('+row.zdbh+')" style="margin-right:10px;">修改</a>';
                    	if(row.scbz=='0')
                    		operateInfo+= '<a href="javascript:setStatus('+row.zdbh+',1)">设为无效</a>';
                    	else
                    		operateInfo+= '<a href="javascript:setStatus('+row.zdbh+',0)">设为有效</a>';
                    	return operateInfo;
                    }}
                    ];
var columnsLiterature= [ { title: '序号',width:'5%',formatter: function (value, row, index) {return index+1;}},
                         { title: '文件名称',field: 'filename'},
                         { title: '作者', field: 'author' },
                         { title: '相关责任人', field: 'contributor' },
                         { title: '出版时间', field: 'publishingtime' },
                         { title: '出版者', field: 'publishinghouse' },	               
                         /*   { title: '文件大小', field: 'size' }, */
                         /*  { title: '发布日期', field: 'published' }, */
                         { title: '状态', formatter: function (value, row, index) {	             	   
                        	 if(row.scbz=='0')
                        		 return '<font style="color:green;">有效</font>';
                        	 else
                        		 return '<font style="color:red;">无效</font>';
                         }},
                         { title: '操作' ,formatter: function (value, row, index) {	
                        	 var operateInfo='<a href="javascript:modifyShowData('+row.zdbh+',1)" style="margin-right:10px;">详情</a>';
                        	 operateInfo+='<a href="javascript:modifyData('+row.zdbh+')" style="margin-right:10px;">修改</a>';
                        	 if(row.scbz=='0')
                        		 operateInfo+= '<a href="javascript:setStatus('+row.zdbh+',1)">设为无效</a>';
                        	 else
                        		 operateInfo+= '<a href="javascript:setStatus('+row.zdbh+',0)">设为有效</a>';
                        	 return operateInfo;
                         }}
                         
                         ];
var resourceid="";
var title="";
var btntext="";
var baseurl="";	
var tablecol="";
var labeltext="";
$(document).ready(function(){
	$('.form_date1').datetimepicker({
		weekStart: 1,
		todayBtn: 1,
		autoclose: 1,
		todayHighlight: 1,
		startView: 2,
		minView: 2,
		forceParse: 0,
		clearBtn:true
	});
	
	$("#imagescdiv").attr("style","display:none;");
	$("#audioscdiv").attr("style","display:none;");
	$("#videoscdiv").attr("style","display:none;");
	$("#threescdiv").attr("style","display:none;");
	$("#literaturescdiv").attr("style","display:none;");
	
	
	resourceid =GetQueryString("resourceid");	
	
	switch(resourceid){
	case '1':
		title="资源上传/影像上传";
		btntext="新增影像";
		baseurl="mbmanageimageServlet";
		tablecol=columns;
		labeltext="新增影像信息";
		$("#imagescdiv").attr("style","display:block;");
		break;
	case '2':
		title="资源上传/音频上传";
		btntext="新增音频";
		baseurl="mbmanageaudiofrequencyServlet";
		tablecol=columns;
		labeltext="新增音频信息";
		$("#audioscdiv").attr("style","display:block;");
		break;
	case '3':
		title="资源上传/视频上传";
		btntext="新增视频";	
		baseurl="mbmanagevideoServlet";
		tablecol=columns;
		labeltext="新增视频信息";
		$("#videoscdiv").attr("style","display:block;");
		break;
	case '4':
		title="资源上传/三维模型上传";
		btntext="新增三维模型";
		baseurl="mbmanagethreedimensionalmodelServlet";
		tablecol=columnsThree;
		labeltext="新增三维模型信息";
		$("#threescdiv").attr("style","display:block;");
		break;
	case '5':
		title="资源上传/文献上传";
		btntext="新增文献";		
		baseurl="mbmanageliteratureServlet";
		tablecol=columnsLiterature;
		labeltext="新增文献信息";
		$("#literaturescdiv").attr("style","display:block;");
		break;
	default:
		
	}
	
	var wjgsjson = ajaxResult("get",false,"../../mbxtglbasetableservlet.getPullData.do",{tn:"mb_gy_wjgs"});
	loadSelect("select[name=fileFormat]",wjgsjson.rows,'id','name');
	var zyqxlxjson = ajaxResult("get",false,"../../mbxtglbasetableservlet.getPullData.do",{tn:"mb_gy_zyqxlx"});
	loadSelect("select[name=rightsType]",zyqxlxjson.rows,'id','name');
	var ypjson = ajaxResult("get",false,"../../mbxtglbasetableservlet.getPullData.do",{tn:"mb_gy_sxcjgs"});
	loadSelect("select[name=audioEF]",ypjson.rows,'id','name');
	var spjson = ajaxResult("get",false,"../../mbxtglbasetableservlet.getPullData.do",{tn:"mb_gy_sxcjgs"});
	loadSelect("select[name=videoEF]",spjson.rows,'id','name');
	
	
	$("#navli").text(title);
	$("#addbtn").text(btntext);
	createTable('#data-table', '../../'+baseurl+'.getData.do', 'id', tablecol,{'pageNumber':1,'pageSize':10});	
	
	$("#image_query_btn").click(function(){
		refreshScTable("#data-table","#imageForm");
	});
	$("#audio_query_btn").click(function(){
		refreshScTable("#data-table","#audioForm");
	});
	$("#video_query_btn").click(function(){
		refreshScTable("#data-table","#videoForm");
	});
	$("#three_query_btn").click(function(){
		refreshScTable("#data-table","#threeForm");
	});
	$("#literature_query_btn").click(function(){
		refreshScTable("#data-table","#literatureForm");
	});
	
});

function addData(){
	switch(resourceid){
	case '1':
		getAddModelHtmlImg();
		break;
	case '2':
		getAddModelHtmlAudio();
		break;
	case '3':
		getAddModelHtmlVideo();
		break;
	case '4':
		getAddModelHtmlThree();
		break;
	case '5':
		getAddModelHtmlLiterature();
		break;
	default:
		
	}		
	$("<input type='hidden'  id='fileid' name='fileid'/>").appendTo("form");
	//$(".file-input .kv-file-upload").hide();
	$("#myModalLabel").text(labeltext);
	//$("#btnAddModi").text("确定增加");
	$("#addModal").modal('show');
}

function modifyData(zdbh,show){
	if(zdbh==null){
		alertFunc("参数错误!");
		return false;
	}
	var templabeltext = '';
	switch(resourceid){
		case '1':
		templabeltext="修改影像信息";
			break;
		case '2':
		templabeltext="修改音频信息";
			break;
		case '3':
		templabeltext="修改视频信息";
			break;
		case '4':
		templabeltext="修改三维模型信息";
			break;
		case '5':
		templabeltext="修改文献信息";
			break;
		default:
	}
	var result=ajaxResult('post',false,baseurl+'.getOneDetail.do',{'zdbh':zdbh});
	if(result.status=='OK'){
		addData();
		$("<input type='hidden' id='zdbh' name='zdbh'/>").appendTo("form");
		$(".col-md-8").prepend("<div style='padding-bottom:10px;'><span>已上传文件：<b>"+result.rows.filename+"</b></span></div>");
		if(resourceid=='1'){
			$(".col-md-8").prepend("<div style='padding-bottom:10px;'><img src='mbgyfileServlet.downFile.do?fileid="+result.rows.fileid+"' style='width:100px;height:100px;'></div>");
		}
		loadData("#uploadForm",result.rows);
		$("#myModalLabel").text(templabeltext);
		$("#btnAddModi").show();
		//$("#btnAddModi").text("确定修改");
		if(show=='1'){
			
			$("#gyscdiv input").prop("disabled","disabled");
			$("#gyscdiv select").prop("disabled","disabled");
			
			//$("input").prop("disabled","disabled");
			//$("select").prop("disabled","disabled");
			
			//$(".input-group-addon").prop("disabled","disabled");
			$("#gyscdiv .input-group-addon").remove();
			$("#gyscdiv .file-input").hide();
			$("#gyscdiv select").css("background-color","#eee");
		}
		$("#addModal").modal('show');
	}else{
		alertFunc(result.msg);
	}		
}


function modifyShowData(zdbh,show){
	if(zdbh==null){
		alertFunc("参数错误!");
		return false;
	}
	var templabeltext = '';
	switch(resourceid){
		case '1':
		templabeltext="影像信息";
			break;
		case '2':
		templabeltext="音频信息";
			break;
		case '3':
		templabeltext="视频信息";
			break;
		case '4':
		templabeltext="三维模型信息";
			break;
		case '5':
		templabeltext="文献信息";
			break;
		default:
	}
	var result=ajaxResult('post',false,baseurl+'.getOneDetail.do',{'zdbh':zdbh});
	if(result.status=='OK'){
		addData();
		$("<input type='hidden' id='zdbh' name='zdbh'/>").appendTo("form");
		$(".col-md-8").prepend("<div style='padding-bottom:10px;'><span>已上传文件：<b>"+result.rows.filename+"</b></span></div>");
		if(resourceid=='1'){
			$(".col-md-8").prepend("<div style='padding-bottom:10px;'><img src='mbgyfileServlet.downFile.do?fileid="+result.rows.fileid+"' style='width:100px;height:100px;'></div>");
		}
		loadData("#uploadForm",result.rows);
		$("#myModalLabel").text(templabeltext);
		$("#btnAddModi").hide();
		$("#btncacel").val('关闭');
		if(show=='1'){
			
			$("#gyscdiv input").prop("disabled","disabled");
			$("#gyscdiv select").prop("disabled","disabled");
			
			//$("input").prop("disabled","disabled");
			//$("select").prop("disabled","disabled");
			
			//$(".input-group-addon").prop("disabled","disabled");
			$("#gyscdiv .input-group-addon").remove();
			$("#gyscdiv .file-input").hide();
			$("#gyscdiv select").css("background-color","#eee");
		}
		$("#addModal").modal('show');
	}else{
		alertFunc(result.msg);
	}		
}






function getAddModelHtmlImg(){
	var html='';
	html+=addInput('title','名称',0);
	html+=addInput('alternative','交替名称',1);
	html+=addInput('subject','主题',0);
	html+=addInput('description','描述',1);
	html+=addTime('created','拍摄时间',0);
	html+=addTime('discovered','发现日期',1);
	html+=addSelect('medium','记录介质类型',0,'mb_gy_jljzlx');
	html+=addSelect('fileFormat','文件格式',1,'mb_gy_wjgs');
	html+=addSelect('sourceType','采集方式',0,'mb_gy_lyfs');
	html+=addInput('sourceForm','出处',1);
	html+=addSelect('language','语种',0,'mb_gy_cyyz');
	html+=addInput('spacearea','空间范围',1);
	html+=addInput('temporal','时间范围',0);
	html+=addInput('publishe','出版者',1);
	html+=addInput('equipment','采集设备',0);
	html+=addInput('storedin','记录介质保存位置',1);
	html+=addSelect('angel','拍摄角度',2,'mb_gy_psjd');
	html+=addFileput('ccUpload','文件上传',1);
	html+=addSelect('rightsType','资源权限类型',0,'mb_gy_zyqxlx');
	$('#uploadForm').html(html);
	imgInput('#ccUpload','mbgyfileServlet.insert.do','fileid');
	datetime(".form_date1");
}

function getAddModelHtmlAudio(){
	var html='';
	html+=addInput('title','名称',0);
	html+=addInput('alternative','交替名称',1);
	html+=addInput('subject','主题',0);
	html+=addInput('description','描述',1);
	html+=addTime('created','拍摄时间',0);
	html+=addTime('discovered','发现日期',1);
	html+=addSelect('medium','记录介质类型',0,'mb_gy_jljzlx');
	html+=addSelect('audioEF','音频编码格式',1,'mb_gy_sxcjgs');
	html+=addSelect('sourceType','采集方式',0,'mb_gy_lyfs');
	html+=addInput('sourceForm','出处',1);
	html+=addSelect('audioChannelLanguage','声道语种',0,'mb_gy_cyyz');
	html+=addSelect('subtitleLanguage','声道语种',1,'mb_gy_cyyz');
	html+=addInput('spacearea','空间范围',0);
	html+=addInput('publishe','出版者',1);
	html+=addInput('temporal','时间范围',0);	
	html+=addInput('equipment','采集设备',1);
	html+=addInput('storedin','记录介质保存位置',0);
	html+=addSelect('angel','拍摄角度',1,'mb_gy_psjd');
	html+=addFileput('ccUpload','文件上传',1);
	html+=addSelect('rightsType','资源权限类型',0,'mb_gy_zyqxlx');
	$('#uploadForm').html(html);
	audioInput('#ccUpload','mbgyfileServlet.insert.do','fileid');
	datetime(".form_date1");		
}

function getAddModelHtmlVideo(){
	var html='';
	html+=addInput('title','名称',0);
	html+=addInput('alternative','交替名称',1);
	html+=addInput('subject','主题',0);
	html+=addInput('description','描述',1);
	html+=addTime('created','拍摄时间',0);
	html+=addTime('discovered','发现日期',1);
	html+=addSelect('medium','记录介质类型',0,'mb_gy_jljzlx');
	html+=addSelect('audioEF','音频编码格式',1,'mb_gy_sxcjgs');
	html+=addSelect('videoEF','视频编码格式',0,'mb_gy_sxcjgs');
	html+=addSelect('sourceType','采集方式',1,'mb_gy_lyfs');
	html+=addInput('sourceForm','出处',0);
	html+=addSelect('audioChannelLanguage','声道语种',1,'mb_gy_cyyz');
	html+=addSelect('subtitleLanguage','声道语种',0,'mb_gy_cyyz');
	html+=addInput('spacearea','空间范围',1);
	html+=addInput('publishe','出版者',0);
	html+=addInput('temporal','时间范围',1);		
	html+=addInput('equipment','采集设备',0);
	html+=addInput('storedin','记录介质保存位置',1);
	html+=addSelect('angel','拍摄角度',0,'mb_gy_psjd');
	html+=addFileput('ccUpload','文件上传',1);
	html+=addSelect('rightsType','资源权限类型',0,'mb_gy_zyqxlx');
	$('#uploadForm').html(html);
	videoInput('#ccUpload','mbgyfileServlet.insert.do','fileid');
	datetime(".form_date1");		
}

function getAddModelHtmlThree(){
	var html='';
	html+=addInput('title','名称',0);
	html+=addInput('alternative','交替名称',1);
	html+=addInput('subject','主题',0);
	html+=addInput('description','描述',1);
	html+=addTime('created','拍摄时间',0);
	html+=addInput('collectionunit','采集单位',1);
	html+=addFileput('ccUpload','文件上传',1);
	html+=addSelect('rightsType','资源权限类型',0,'mb_gy_zyqxlx');
	$('#uploadForm').html(html);
	fileuploadInput('#ccUpload','mbgyfileServlet.insert.do','fileid');
	datetime(".form_date1");
}

function getAddModelHtmlLiterature(){
	var html='';
	html+=addInput('filename','文件名称',0);
	html+=addInput('author','作者',1);
	html+=addInput('contributor','相关责任人',0);
	html+=addInput('publishingtime','出版时间',1);
	html+=addInput('publishinghouse','出版者',2);
	html+=addFileput('ccUpload','文件上传',1);		
	html+=addSelect('rightsType','资源权限类型',0,'mb_gy_zyqxlx');
	$('#uploadForm').html(html);
	fileuploadInput('#ccUpload','mbgyfileServlet.insert.do','fileid');
}

function addConfirm(){
	//var params =$('#gyscdiv #uploadForm').serializeObject();
	var params =$('#uploadForm').serializeObject();
	if(params.fileid==null || params.fileid==""){
		alertFunc("请先上传文件！");
		return false;
	}
	var word="";
	var url="";
	if(params.zdbh == undefined){
		word='增加成功！';
		url=".insert.do";
	}else{
		word='修改成功！';
		url=".update.do";
	}			
	var result=ajaxResult('post',false,baseurl+url,params);
	if(result.status=='OK'){
		alertFunc(word,function(){
			$('#data-table').bootstrapTable('refresh');
			$('#addModal').modal('hide');		
			datafileid="";
		});
	}else{
		alertFunc(result.msg);
	}
}	

function setStatus(zdbh,scbz){
	if(zdbh==null || scbz==null){
		alertFunc("参数错误!");
		return false;
	}
	var url="";
	if(scbz==0){
		url='.setvalid.do';
	}else{
		url='.setinvalid.do';
	}
	var result=ajaxResult('post',false,baseurl+url,{'zdbh':zdbh,'scbz':scbz});
	if(result.status=='OK'){
		alertFunc('设置成功！',function(){
			$('#data-table').bootstrapTable('refresh');								
		});
	}else{
		alertFunc(result.msg);
	}
}